package com.medicine.controller;

import java.io.IOException;

import net.sf.json.JSONObject;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSON;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import pagination.Page;
import po.Equipment;
import requestvo.SuperAdminReqVo;
@Controller
public class SuperAdminController extends BaseController{
	
	@RequestMapping("/superAdminInfo")
	public void findSuperAdminInfo(SuperAdminReqVo superAdminReqVo,HttpServletResponse response) throws IOException{
		try{
			Page<SuperAdminReqVo> page=superAdminService.findSuperAdminInfo(superAdminReqVo);	
			JSONObject jsonObject=new JSONObject();
			jsonObject.element("rows", page.getResults());
			jsonObject.element("total", page.getTotalRecord());
			response.setCharacterEncoding("UTF-8");  
			response.setContentType("application/json; charset=utf-8");  
			response.getWriter().print(jsonObject.toString());
			}catch(Exception e){
				throw e;
		}
		
	}
	@RequestMapping("/updateSuperAdminInfo")
	public void updateSuperAdminInfo(SuperAdminReqVo superAdminReqVo,HttpServletResponse response) throws IOException{
		superAdminService.updateSuperAdminInfo(superAdminReqVo);
		response.sendRedirect("superAdmin.html");
	}
	@RequestMapping("/addSuperAdminInfo")
	public void addSuperAdminInfo(SuperAdminReqVo superAdminReqVo,HttpServletResponse response,HttpServletRequest request) throws IOException{		
		String sgly_no=superAdminService.ifHasSuperAdmin(superAdminReqVo.getSgly_no()); //sgly_no有值表示已存在
		if(sgly_no!=null||!sgly_no.equals("")){
			response.sendRedirect("500.jsp"); //不允许插入
		}else{
			superAdminService.addSuperAdminInfo(superAdminReqVo);
			request.setAttribute("superAdminReqVo", superAdminReqVo);
			response.sendRedirect("superAdmin.html"); 
		}
		
		
	}
	@RequestMapping("/delSuperAdminInfo")
	public void delSuperAdminInfo(String ids,HttpServletResponse response) throws IOException{
		String[] id=ids.split(",");
		String[] integers=new String[id.length];
		for(int i=0;i<id.length;++i)
			integers[i]=id[i];
		superAdminService.delSuperAdminInfo(integers);
		response.sendRedirect("superAdmin.html");
	}
	/*@RequestMapping("/checktechxx")
	public void checkYPBM(Integer tech_no,HttpServletResponse response) throws IOException{
		SuperAdminReqVo ypxx= superAdminService.getTeacherReqVo(yPBM);
		if(ypxx==null)
			response.getWriter().print("null");
		else
			response.getWriter().print(ypxx.getyPMC());
	}*/
	
/*	@RequestMapping("/findAllYpxx")
	public void findAllYpxx(HttpServletResponse response) throws IOException{
		
		response.setCharacterEncoding("UTF-8");  
		response.setContentType("application/json; charset=utf-8"); 
		JsonObject jsonObject=new JsonObject();
		JSONArray jsonArray=JSONArray.fromObject(superAdminService.findAll());
		response.getWriter().print(jsonArray.toString());
	}*/
	
}
